package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.CheckIn;
import com.ruoyi.system.service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/check/in")
public class CheckInController extends BaseController {
    @Autowired
    private CheckInService checkInService;

    @GetMapping("/list")
    public TableDataInfo listCheckIn(CheckIn checkIn){
        startPage();
        return getDataTable(checkInService.listCheckIn(checkIn));
    }

    @PostMapping("/insertUpCheck")
    @Transactional
    public int  insertUpCheckIn(@RequestBody CheckIn checkIn){
        CheckIn checkIn1 = checkInService.selectMorningByDate(checkIn);
        //如果为空,允许打卡
        if (ObjectUtils.isEmpty(checkIn1)) {
            return checkInService.insertUpCheck(checkIn);
        }
        return 0;
    }

    @PostMapping("/upDownCheck")
    @Transactional
    public int  upDownCheckIn(@RequestBody CheckIn checkIn){
        CheckIn checkIn1 = checkInService.selectAfternoonByDate(checkIn);
        if (ObjectUtils.isEmpty(checkIn1)) {
            //如果为空,不允许打卡
            return 0;
        }
        return checkInService.upDownCheck(checkIn);
    }
}
